﻿/* Project: Side Scrolling Shooter
 * Enemy subclass 2: Ground enemy
 * Last Update: 4/12/11,11:16PM
 */

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace TheFifthSpace
{
    public class Enemy2 : Enemy
    {
        //private SpriteBatch spriteBatch;
        private Vector2 offset;
        public override Vector2 Offset
        {
            get
            {
                return offset;
            }
            set
            {
                offset.X = value.X;
                offset.Y = value.Y;
            }
        }


        public Enemy2(Game g, Vector2 p)
            : base(g, p)
        {
            Random r = new Random();
            speed = -50 - r.Next(50);
            // Speed varies
            LoadContent();
            pointValue = 15;
        }

        // LOAD CONTENT
        protected override void LoadContent()
        {
            sprite = MainGame.enemy2Sprite;
            //spriteBatch = MainGame.spriteBatch;
            offset = new Vector2(sprite.Width / 2, sprite.Height / 2);
            //base.LoadContent();
        }

        // DRAW
        public override void Draw(GameTime gameTime)
        {
            MainGame.spriteBatch.Begin();
            MainGame.spriteBatch.Draw(sprite, Position - offset, Color.White);
            MainGame.spriteBatch.End();
            //base.Draw(gameTime);
        }

        public override bool CollideWithPlayer(Rectangle pRect)
        {
            Rectangle myRect = new Rectangle(
                (int)(posX - offset.X), (int)(posY - offset.Y),
                sprite.Width, sprite.Height);
            if (myRect.Intersects(pRect)) return true;
            else return false;
        }

        // Aims at player
        public override void Fire()
        {
            Vector2 direction = RelativeToPlayer();
            MainGame.EnemyBullets.Add(new EnemyBullet(Game, Position, direction));
        }
    }
}